#coding=utf-8
'''
gelerate_ip_addr 可根据输入的ip生成n个ip数组
例如：gelerate_ip_addr 1.1.1.1 500  可选参数：起始位置 结束位置 只有一位时默认为结束位
可以生成 1.1.1.1 - 1.1.1.2.244的ip
'''

def gelerate_ip_add(IP,n,*args):
    ip_list = [IP]    #用于返回的列表
    date = IP.split('.')
    four = int(date[3])  # ip地址的第四位
    three = int(date[2])
    two = int(date[1])
    one = int(date[0])
    star = 1            #生成ip起始位置
    end = 255           #生成ip结束位置
    if len(args) == 2:
        star = args[0]
        end = args[1]
    elif len(args) == 1:
        end = args[0]
    i = 1
    for i in range(1,n+1):
        four += 1
        if four > end:
            three += 1
            four = star
            if three > 255:
                two += 1
                three = 0
                if two > 255:
                    one += 1
                    two = 0
                    if one > 255:
                        one = 1
        link_ip = "%d.%d.%d.%d" %( one,two,three,four)
        ip_list.append(link_ip)
    return ip_list

if __name__=="__main__":
    IP = "1.1.254.1"
    n = 1000
    # IP = raw_input("请输入起始ip：")
    # n = input("请输入生成ip个数")
    ip_show = gelerate_ip_add(IP,n )
    print ip_show